
package com.dps.omc.action;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dps.omc.service.IOsTypeService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dps.common.domain.view.BizData4Page;
import com.dps.omc.model.OsType;
import com.dps.common.utils.IdGenerator;
import com.dps.common.utils.JsonResult;
import com.dps.common.utils.PageParam;
import com.dps.common.utils.Constants;

@Controller
public class OsTypeAction extends AbstractAdminController<IOsTypeService>{

    @Autowired
    private IOsTypeService osTypeService;
    
    @RequestMapping(value="/ostype/list")
    public String list(OsType osType,ModelMap model,PageParam pageParam,HttpServletRequest request,HttpServletResponse response){

        //获取参数
    	Map<String, Object> conditions = getQueryMap(osType); 	
    	BizData4Page<OsType> pageCtx = doPage(model, conditions, pageParam);
    	model.addAttribute("osType", osType);
    	return "/module/ostype/list";
    }    
    
    @RequestMapping(value="/ostype/add")
    public String add(ModelMap model,HttpServletRequest request,HttpServletResponse response){

    	model.addAttribute("osType", new OsType());
        return "module/ostype/edit";
    }    
    
    @RequestMapping(value="/ostype/edit")
    public String edit(String id,ModelMap model,HttpServletRequest request,HttpServletResponse response){
    	
    	OsType osType = osTypeService.fetch(id);
    	model.addAttribute("osType", osType);
        return "module/ostype/edit";
    }    
    
    @RequestMapping(value="/ostype/save")
    @ResponseBody
    public String save(HttpServletRequest request,OsType osType){
		boolean isAddNew = StringUtils.isBlank(osType.getId())?true:false;
		if(isAddNew)
		{
			osType.setId(IdGenerator.createNewId());
			osTypeService.add(osType);
		}
		else
		{
			osTypeService.update(osType);
		}
        return JsonResult.saveSuccessClose(Constants.MAIN_TAB).toString();
    }    
    
    @RequestMapping(value="/ostype/delete")
    @ResponseBody
    public String delete(String ids,HttpServletRequest request){
    	
    	osTypeService.deleteByIds(ids);
    	return JsonResult.DELETE_SUCCESS.toString();
    }       
	
    protected Map getQueryMap(OsType osType)
    {
    	Map<String, Object> conditions = new HashMap();
    	
		conditions.put("typeName", osType.getTypeName());		
		conditions.put("createrId", osType.getCreaterId());		
		conditions.put("createrName", osType.getCreaterName());		
		conditions.put("createDate", osType.getCreateDate());		
    	return conditions;
    }

    @Override
    protected IOsTypeService getMainService() {
        return osTypeService;
    }

    @Override
    protected String getMainObjName() {
        return "ostype";
    }

    @Override
    protected String getViewTitle() {
        return "ostype";
    }
}
